package cn.ffcs.unm.epiboly.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.epiboly.dao.OutsourcingDao;
import cn.ffcs.unm.epiboly.model.OutStaffContract;
import cn.ffcs.unm.epiboly.model.OutStaffCost;
import cn.ffcs.unm.epiboly.model.OutStaffInfo;
import cn.ffcs.unm.epiboly.model.OutStaffMainTable;
import cn.ffcs.unm.epiboly.model.OutStaffQualification;
import cn.ffcs.unm.epiboly.model.OutStaffTrainInfo;
import cn.ffcs.unm.epiboly.model.OutStaffWork;
import cn.ffcs.unm.epiboly.model.OutsourcingCompany;
import cn.ffcs.unm.epiboly.model.UtsourcingContract;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("outsourcingDao")
public class OutsourcingDaoImpl extends BaseDaoImpl implements OutsourcingDao {

	@Override
	public PageInfo queryPageInfoByUtsourcingContract(
			UtsourcingContract utsourcingContract, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder(" select * from view_WB_CT_MANAGE where 1 = 1 ");
		
		List<Object> params = new ArrayList<Object>();
		if (null != utsourcingContract) {
			if (!StrUtil.isEmpty(utsourcingContract.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(utsourcingContract.getMonthId());
			}
			if (!StrUtil.isEmpty(utsourcingContract.getCtName())) {
				sb.append(" AND CTNAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(utsourcingContract
								.getCtName()) + "%");
			}
			if (!StrUtil.isEmpty(utsourcingContract.getCtCode())) {
				sb.append(" AND ctcode LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(utsourcingContract
								.getCtCode()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, UtsourcingContract.class);
	}

	@Override
	public PageInfo queryPageInfoByOutsourcingCompany(
			OutsourcingCompany outsourcingCompany, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_WB_CORP where 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != outsourcingCompany) {
			if (!StrUtil.isEmpty(outsourcingCompany.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(outsourcingCompany.getMonthId());
			}
			if (!StrUtil.isEmpty(outsourcingCompany.getUnitcode())) {
				sb.append(" AND UNITCODE LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outsourcingCompany
								.getUnitcode()) + "%");
			}
			if (!StrUtil.isEmpty(outsourcingCompany.getUnitname())) {
				sb.append(" AND UNITNAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outsourcingCompany
								.getUnitname()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutsourcingCompany.class);
	}

	@Override
	public PageInfo queryPageInfoByOutStaffCost(OutStaffCost outStaffCost,
			int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_WB_PSN_COST_B where 1 = 1 ");

		List<Object> params = new ArrayList<Object>();
		if (null != outStaffCost) {
			if (!StrUtil.isEmpty(outStaffCost.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(outStaffCost.getMonthId());
			}
			if (!StrUtil.isEmpty(outStaffCost.getPsnName())) {
				sb.append(" AND psnName LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffCost.getPsnName())
						+ "%");
			}
			if (!StrUtil.isEmpty(outStaffCost.getPsnCode())) {
				sb.append(" AND psnCode LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffCost.getPsnCode())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutStaffCost.class);
	}

	@Override
	public PageInfo queryPageInfoByOutStaffContract(
			OutStaffContract outStaffContract, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append("select * from  VIEW_WB_PSN_PERCON where 1 = 1 ");

		List<Object> params = new ArrayList<Object>();
		if (null != outStaffContract) {
			if (!StrUtil.isEmpty(outStaffContract.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(outStaffContract.getMonthId());
			}
			if (!StrUtil.isEmpty(outStaffContract.getPkPsnMsg())) {
				sb.append(" AND pkPsnMsg LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffContract
								.getPkPsnMsg()) + "%");
			}
			if (!StrUtil.isEmpty(outStaffContract.getCtCode())) {
				sb.append(" AND ctCode = ? ");
				params.add(outStaffContract.getCtCode());
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutStaffContract.class);
	}

	@Override
	public PageInfo queryPageInfoByOutStaffQualification(
			OutStaffQualification outStaffQualification, int currentPage,
			int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_WB_PSN_VOCQUA where 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != outStaffQualification) {
			if (!StrUtil.isEmpty(outStaffQualification.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(outStaffQualification.getMonthId());
			}
			if (!StrUtil.isEmpty(outStaffQualification.getPkPsnMsg())) {
				sb.append(" AND pkPsnMsg LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffQualification
								.getPkPsnMsg()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutStaffQualification.class);
	}

	@Override
	public PageInfo queryPageInfoByOutStaffTrainInfo(
			OutStaffTrainInfo outStaffTrainInfo, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder(" select * from view_WB_PSN_TRAMSG where 1 = 1 ");
		
		List<Object> params = new ArrayList<Object>();
		if (null != outStaffTrainInfo) {
			if (!StrUtil.isEmpty(outStaffTrainInfo.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(outStaffTrainInfo.getMonthId());
			}
			if (!StrUtil.isEmpty(outStaffTrainInfo.getPkPsnMsg())) {
				sb.append(" AND pkPsnMsg LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffTrainInfo
								.getPkPsnMsg()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutStaffTrainInfo.class);
	}

	@Override
	public PageInfo queryPageInfoByOutStaffInfo(OutStaffInfo outStaffInfo,
			int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder(
				" select * from  VIEW_WB_PSN_MSG where 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != outStaffInfo) {
			if (!StrUtil.isEmpty(outStaffInfo.getMonthId())) {
				sb.append(" AND MONTHID = ? ");
				params.add(outStaffInfo.getMonthId());
			}
			if (!StrUtil.isEmpty(outStaffInfo.getPsnname())) {
				sb.append(" AND PSNNAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffInfo.getPsnname())
						+ "%");
			}
			if (!StrUtil.isEmpty(outStaffInfo.getPsncode())) {
				sb.append(" AND PSNCODE = ? ");
				params.add(outStaffInfo.getPsncode());
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutStaffInfo.class);
	}

	@Override
	public PageInfo queryPageInfoByOutStaffWork(OutStaffWork outStaffWork,
			int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_WB_PSN_WORK where 1 = 1 ");
				
		List<Object> params = new ArrayList<Object>();
		if (null != outStaffWork) {
			if (!StrUtil.isEmpty(outStaffWork.getMonthId())) {
				sb.append(" AND MONTHID = ? ");
				params.add(outStaffWork.getMonthId());
			}
			if (!StrUtil.isEmpty(outStaffWork.getPkPsnMsg())) {
				sb.append(" AND pkPsnMsg LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffWork.getPkPsnMsg())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutStaffWork.class);
	}

	@Override
	public PageInfo queryPageInfoByOutStaffMainTable(
			OutStaffMainTable outStaffMainTable, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder(
				" select * from VIEW_WB_PSN_COST_H where 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != outStaffMainTable) {
			if (!StrUtil.isEmpty(outStaffMainTable.getMonthId())) {
				sb.append(" AND MONTHID LIKE ? ");
				params.add(outStaffMainTable.getMonthId());
			}
			if (!StrUtil.isEmpty(outStaffMainTable.getManagers())) {
				sb.append(" AND ja1.MANAGERS LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(outStaffMainTable
								.getManagers()) + "%");
			}
			if (!StrUtil.isEmpty(outStaffMainTable.getPeriod())) {
				sb.append(" ja1.YEAR = ? ");
				params.add(StringEscapeUtils.escapeSql(outStaffMainTable
						.getPeriod()));
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, OutStaffMainTable.class);
	}

}
